package com.survivor.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;

public class AppMgr {
	
	private List<AppModel> appList;
	
	private static AppMgr _instance;
	
	public static AppMgr getInstance()
	{
		if(_instance == null)
			_instance = new AppMgr();
		return _instance;
		
	}
	
	
	private AppMgr()
	{
		appList = new ArrayList<AppModel>();
	}
	
	public void initAppList(Context context)
	{
		final PackageManager packageManager = context.getPackageManager();

        final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        final List<ResolveInfo> apps = packageManager.queryIntentActivities(mainIntent, 0);
        for(int i = 0; i < apps.size(); i++)
        {
        	AppModel app = new AppModel();
        	BitmapDrawable b;
        	app.icon = ((BitmapDrawable)apps.get(i).loadIcon(packageManager)).getBitmap();
        	app.title = apps.get(i).loadLabel(packageManager).toString();
        	System.out.println(app.title);
        	appList.add(app);
        }
	}

}
